    //
//  BlendModeView.m
//  QuartzStudy
//
//  Created by longhuihu on 11-6-21.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "BlendViewController.h"
#import "BlendShape.h"

@implementation BlendViewController

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	shape = [[BlendShape alloc] initWithFrame:CGRectMake(0, 0, 320, 200)];
	[self.view addSubview:shape];
	
	UIPickerView *picView = [[UIPickerView alloc] initWithFrame: CGRectMake(0, 310, 320,200)];
	picView.dataSource = self;	
	picView.delegate = self;	
	picView.showsSelectionIndicator = YES;
	[self.view addSubview:picView];
	[picView release];
	/*kCGBlendModeNormal,
    kCGBlendModeMultiply,
    kCGBlendModeScreen,
    kCGBlendModeOverlay,
    kCGBlendModeDarken,
    kCGBlendModeLighten,
    kCGBlendModeColorDodge,
    kCGBlendModeColorBurn,
    kCGBlendModeSoftLight,
    kCGBlendModeHardLight,
    kCGBlendModeDifference,
    kCGBlendModeExclusion,
    kCGBlendModeHue,
    kCGBlendModeSaturation,
    kCGBlendModeColor,
    kCGBlendModeLuminosity, ...	*/
	blendModes = [NSDictionary dictionaryWithObjectsAndKeys:@"kCGBlendModeNormal",[NSNumber numberWithInt:kCGBlendModeNormal],
				  @"kCGBlendModeMultiply",[NSNumber numberWithInt:kCGBlendModeMultiply],
				  @"kCGBlendModeScreen",[NSNumber numberWithInt:kCGBlendModeScreen],
				  @"kCGBlendModeOverlay",[NSNumber numberWithInt:kCGBlendModeOverlay],
				  @"kCGBlendModeDarken",[NSNumber numberWithInt:kCGBlendModeDarken],
				  @"kCGBlendModeLighten",[NSNumber numberWithInt:kCGBlendModeLighten],
				  @"kCGBlendModeColorDodge",[NSNumber numberWithInt:kCGBlendModeColorDodge],
				  @"kCGBlendModeColorBurn",[NSNumber numberWithInt:kCGBlendModeColorBurn],
				  @"kCGBlendModeSoftLight",[NSNumber numberWithInt:kCGBlendModeSoftLight],
				  @"kCGBlendModeHardLight",[NSNumber numberWithInt:kCGBlendModeHardLight],
				  @"kCGBlendModeExclusion",[NSNumber numberWithInt:kCGBlendModeExclusion],
				  @"kCGBlendModeHue",[NSNumber numberWithInt:kCGBlendModeHue],nil];
	[blendModes retain];

}

#pragma mark UIPickerView dataSource&delegate
// returns the number of 'columns' to display.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
	return 1;
}

// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
	return [blendModes count];
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
{
	return [[blendModes allValues] objectAtIndex:row];
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
	NSNumber *value = [[blendModes allKeys] objectAtIndex:row];
	shape.blendMode = [value intValue];
	[shape setNeedsDisplay];
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
	[shape release];
	shape = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
